﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.UpdateServer
{
    public class PatchUtil
    {
        /// <summary>
        /// 获取增量更新包的路径
        /// </summary>
        /// <param name="product"></param>
        /// <param name="appType"></param>
        /// <param name="fromVersion"></param>
        /// <param name="toVersion"></param>
        /// <returns></returns>
        public static string GetIncrementalPatchFileAbsolutePath(string baseDirectory,
            string product,
            string appType,
            string fromVersion,
            string toVersion)
        {
            string path = string.Format("{0}//Patchs//{1}//{2}//Patch_{3}-{4}.zip",
                baseDirectory,
                product,
                appType,
                new Version(fromVersion).ToString(4),
                new Version(toVersion).ToString(4));

            return path;
        }

        /// <summary>
        /// 获取包的名称
        /// </summary>
        /// <param name="fromVersion"></param>
        /// <param name="toVersion"></param>
        /// <returns></returns>
        public static string GetIncrementalPatchFileName(string fromVersion,
            string toVersion)
        {
            string path = string.Format("Patch_{0}-{1}.rar",new Version(fromVersion).ToString(4),
                new Version(toVersion).ToString(4));

            return path;
        }

        public static string GetFullPatchFileAbsolutePath(string baseDirectory,
            string product,
            string appType,
            string toVersion)
        {
            string path = string.Format("{0}//Patchs//{1}//{2}//Patch_Full-{3}.zip",
                baseDirectory,
                product,
                appType,
                new Version(toVersion).ToString(4));

            return path;
        }

        /// <summary>
        /// 获取包的名称
        /// </summary>
        /// <param name="toVersion"></param>
        /// <returns></returns>
        public static string GetFullPatchFileName(string toVersion)
        {
            string path = string.Format("Patch_Full-{0}.rar", new Version(toVersion).ToString(4));

            return path;
        }

        /// <summary>
        /// 获取程序的最新版本信息文件
        /// </summary>
        /// <param name="baseDirectory"></param>
        /// <param name="product"></param>
        /// <param name="appType"></param>
        /// <returns></returns>
        public static string GetVersionFileAbsolutePath(string baseDirectory, string product, string appType)
        {
            string path = string.Format("{0}//Patchs//{1}//{2}//version.xml",
                baseDirectory,
                product,
                appType);

            return path;
        }
    }
}
